package com.bdk.middle.tenant.web;


import com.bdk.middle.common.domain.PageDO;
import com.bdk.middle.common.result.ResultDO;
import com.bdk.middle.common.result.web.ObjectResponse;
import com.bdk.middle.tenant.api.domain.TenantPositionDO;
import com.bdk.middle.tenant.api.query.TenantPositionQueryDO;
import com.bdk.middle.tenant.service.TenantPositionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * <p>
 * 用户登录表 前端控制器
 * </p>
 *
 * @author Reagan
 * @since 2021-01-23
 */

@Api(tags = "租户职位相关接口")
@RestController
@RequestMapping("/TenantPosition_position")
public class TenantPositionController {

    @Autowired
    private TenantPositionService tenantPositionService;
    @ApiOperation(value="租户职位新增", notes="租户职位新增")
    @RequestMapping(value="/add.html", method = RequestMethod.POST)
    public @ResponseBody ObjectResponse add(@RequestBody TenantPositionDO domain) {

        ObjectResponse response = new ObjectResponse();

        ResultDO result = tenantPositionService.add(domain);

        if(!result.isSuccess()) {
            response.setStatus(result.getErrorCode().getCode());
            response.setMsg(result.getErrorCode().getMsg());
        }
        return response;
    }
    @ApiOperation(value="租户职位编辑", notes="租户职位编辑")
    @RequestMapping(value="/edit.html", method = RequestMethod.POST)
    public @ResponseBody ObjectResponse edit(@RequestBody TenantPositionDO domain) {

        ObjectResponse response = new ObjectResponse();

        ResultDO result = tenantPositionService.edit(domain);

        if(!result.isSuccess()) {
            response.setStatus(result.getErrorCode().getCode());
            response.setMsg(result.getErrorCode().getMsg());
        }
        return response;
    }
    @ApiOperation(value="租户职位删除", notes="租户职位删除")
    @RequestMapping(value="/delete.html", method = RequestMethod.POST)
    public @ResponseBody ObjectResponse delete(@RequestBody TenantPositionDO domain) {

        ObjectResponse response = new ObjectResponse();

        ResultDO result = tenantPositionService.remove(domain.getId(), null);

        if(!result.isSuccess()) {
            response.setStatus(result.getErrorCode().getCode());
            response.setMsg(result.getErrorCode().getMsg());
        }
        return response;
    }
    @ApiOperation(value="租户职位详细", notes="租户职位详情")
    @RequestMapping(value="/detail.html", method = RequestMethod.POST)
    public @ResponseBody ObjectResponse detail(@RequestBody TenantPositionDO domain) {

        ObjectResponse<TenantPositionDO> response = new ObjectResponse();

        ResultDO result = tenantPositionService.get(domain.getId());

        if(!result.isSuccess()) {
            response.setStatus(result.getErrorCode().getCode());
            response.setMsg(result.getErrorCode().getMsg());
        } else {
            response.setData((TenantPositionDO) result.getModel(ResultDO.FIRST_MODEL_KEY));
        }
        return response;
    }
    @ApiOperation(value="租户职位列表", notes="租户职位列表")
    @RequestMapping(value="/list.html", method = RequestMethod.POST)
    public @ResponseBody ObjectResponse list(@RequestBody TenantPositionQueryDO domain) {

        ObjectResponse<PageDO<TenantPositionDO>> response = new ObjectResponse();

        ResultDO result = tenantPositionService.find(domain);

        if(!result.isSuccess()) {
            response.setStatus(result.getErrorCode().getCode());
            response.setMsg(result.getErrorCode().getMsg());
        } else {
            response.setData((PageDO<TenantPositionDO>) result.getModel(ResultDO.FIRST_MODEL_KEY));
        }
        return response;
    }

}

